Skip to content

Computer Graphics Linear Algebra Review


CG-Math-Review

Vectors

Vectors are mathematical objects that have both a magnitude (size) and a direction. They are widely used in computer graphics for representing points, directions, velocities, and more in 2D, 3D, or higher-dimensional spaces.

Vector Normalization

Normalization is the process of converting a vector to a unit vector (a vector with a magnitude of 1) while maintaining its direction. This is often useful in shading calculations or directional movement.

To normalize a vector v:

v^=vv

Where:

  • v is the original vector.
  • v is the magnitude (or length) of the vector, calculated as:v=vx2+vy2+vz2$$(in3D)

Cartesian coordinates are used to describe points in a 2D or 3D space as tuples of numbers (x, y) or (x, y, z). In vector representation, they are used to describe the components of a vector.

For example:

  • A point in 2D space: p=(x,y)
  • A point in 3D space: p=(x,y,z)

Vector Multiplication

Vector multiplication comes in three major forms:

  1. Scalar (dot) product: Produces a scalar value, useful for projections.
  2. Vector (cross) product: Produces a new vector orthogonal to the two input vectors.
  3. Scalar multiplication: A vector is multiplied by a scalar value.

Dot (Scalar) Product

The dot product of two vectors produces a single scalar value and is a measure of how much one vector extends in the direction of another. It is calculated using:

\mathbf{a} \cdot \mathbf{b} = a_x b_x + a_y b_y + a_z b_z$$ (in 3D) ### Dot Product in Cartesian Coordinates For two vectors $\mathbf{a} = (a_x, a_y, a_z)$ and $\mathbf{b} = (b_x, b_y, b_z)$, the dot product is: $$\mathbf{a} \cdot \mathbf{b} = a_x b_x + a_y b_y + a_z b_z

Dot Product for Projection

The dot product can also be used to compute the projection of one vector onto another:

Projection of a onto b=abb

In vector form, the projected vector is:

Projb(a)=abb2b

Cross (Vector) Product

In 3D, the cross product of two vectors produces a new vector that is perpendicular to both of the input vectors. The magnitude of the result is equal to the area of the parallelogram formed by the two vectors.

a×b=|ijkaxayazbxbybz|

Where i, j, and k are the unit vectors of the x, y, and z axes.

Cross Product: Properties

  1. a×b=(b×a)
  2. a×a=0 (zero vector)
  3. The magnitude of the cross product is:a×b=absinθWhere θ is the angle between the vectors.
  4. The direction of the resultant vector follows the right-hand rule.

Orthonormal Coordinate Frames

An orthonormal coordinate frame is a set of basis vectors that are:

  1. Orthogonal: Each pair of vectors is perpendicular.
  2. Normalized: Each basis vector has a magnitude of 1.

In 3D computer graphics, orthonormal frames (like the basis vectors i, j, and k) are often used for camera orientation, transformation matrices, and object alignment.


Matrix

A matrix is a 2D array of numbers that can represent a variety of transformations or systems of equations. In computer graphics, matrices are widely used to perform linear transformations like scaling, rotation, and translation.

Matrix-Matrix Multiplication

The product of two matrices A (of size m×n) and B (of size n×p) is a new matrix C=AB (of size m×p):

Cij=k=1nAikBkj

Matrix-Vector Multiplication

A matrix can transform a vector by the operation y=Ax, where A is a matrix and x is a vector.

Example: For A=[abcd] and x=[xy],

Ax=[abcd][xy]=[ax+bycx+dy]

Transpose of a Matrix

The transpose of a matrix A is obtained by flipping its rows and columns:

AijT=Aji

Identity Matrix and Inverses

  1. Identity Matrix: An identity matrix I is a square matrix with 1s on the diagonal and 0s elsewhere:

    I=[100010001]
  2. Inverse Matrix: For a square matrix A, the inverse A1 satisfies:

    AA1=A1A=I

    Not all matrices have inverses; a matrix must be non-singular (determinant 0).

Vector Multiplication in Matrix Form

The dot product of two vectors can also be represented as a matrix multiplication:

ab=aTb

For example:

a=[axay],b=[bxby]aTb=[axay][bxby]=axbx+ayby